package wzr;
import DataBase.*;
import java.util.*;
import wxy.*;

import java.awt.Container;
import java.awt.event.*;

import javax.swing.*;

import mainWindow.MainFrame;
import javax.swing.text.*;
public class AdvSenseBlock extends SenseBlock 
{
	public AdvSenseBlock(AdvSense ads, boolean hl, int num)
	{
		super(ads, hl, num);
		advSense = ads;
		initAdv();
	}
	private final AdvSense advSense;
	private void initAdv()
	{
		if (advSense.hasStemAjectives())
		{
			Box stemAjectivesPanel = Box.createVerticalBox();
			//stemAjectivesPanel.setLayout(new BoxLayout(stemAjectivesPanel, BoxLayout.Y_AXIS));
			Box[] str = new Box[advSense.getStemAjectives().size()];
			for (int i = 0; i < advSense.getStemAjectives().size(); i ++)
			{
				str[i] = Box.createHorizontalBox();
				//str[i].setLayout(new BoxLayout(str[i], BoxLayout.X_AXIS));
				str[i].add(new JLabel(i + 1 + "."));
				JLabel[] word = new JLabel[advSense.getStemAjectives().get(i).get_Words().size()];
				for (int j = 0; j < advSense.getStemAjectives().get(i).get_Words().size(); j ++)
				{
					word[j] = new JLabel(advSense.getStemAjectives().get(i).get_Words().get(j));
					final String newWord = word[j].getText();
					word[j].addMouseListener(new MouseAdapter()
					{
						public void mouseClicked(MouseEvent e) 
						{
							Container container = getTopLevelAncestor();
							if (container instanceof MainFrame)
							{
								((MainFrame)container).addWord(newWord);
							}
						}
					});
					str[i].add(word[j]);
					str[i].add(Box.createHorizontalStrut(20));
				}
				str[i].add(Box.createHorizontalGlue());
				stemAjectivesPanel.add(str[i]);
			}
			stemAjectivesPanel.add(Box.createVerticalGlue());
			stemAjectivesPanel.setBackground(null);
			stemAjectivesPanel.setOpaque(false);
			relation.addTab("Stem Ajectives", stemAjectivesPanel);
		}
		if (advSense.hasAntonyms())
		{
			Box antonymsPanel = Box.createVerticalBox();
			//antonymsPanel.setLayout(new BoxLayout(antonymsPanel, BoxLayout.Y_AXIS));
			Box[] str = new Box[advSense.getAntonyms().size()];
			for (int i = 0; i < advSense.getAntonyms().size(); i ++)
			{
				str[i] = Box.createHorizontalBox();
				//str[i].setLayout(new BoxLayout(str[i], BoxLayout.X_AXIS));
				str[i].add(new JLabel(i + 1 + "."));
				JLabel[] word = new JLabel[advSense.getAntonyms().get(i).get_Words().size()];
				for (int j = 0; j < advSense.getAntonyms().get(i).get_Words().size(); j ++)
				{
					word[j] = new JLabel(advSense.getAntonyms().get(i).get_Words().get(j));
					final String newWord = word[j].getText();
					word[j].addMouseListener(new MouseAdapter()
					{
						public void mouseClicked(MouseEvent e) 
						{
							Container container = getTopLevelAncestor();
							if (container instanceof MainFrame)
							{
								((MainFrame)container).addWord(newWord);
							}
						}
					});
					str[i].add(word[j]);
					str[i].add(Box.createHorizontalStrut(20));
				}
				str[i].add(Box.createHorizontalGlue());
				antonymsPanel.add(str[i]);
			}
			antonymsPanel.add(Box.createVerticalGlue());
			antonymsPanel.setBackground(null);
			antonymsPanel.setOpaque(false);
			relation.addTab("Antonyms", antonymsPanel);
		}
		if (advSense.hasUsages() || advSense.hasRegions() || advSense.hasUsages())
		{
			JTextPane domainPane = new JTextPane();
			domainPane.setBackground(null);
			domainPane.setOpaque(false);
			domainPane.setEditable(false);
			String tmp = new String("");
			if (advSense.hasTopics())
			{
				tmp += "Topics: ";
				for (int i = 0; i < advSense.getTopics().size(); i ++)
				{
					for (int j = 0; j < advSense.getTopics().get(i).get_Words().size(); j ++)
					{
						if (j == advSense.getTopics().get(i).get_Words().size() - 1)
						{
							tmp += (advSense.getTopics().get(i).get_Words().get(j) + ";\n");
						}
						else
						{
							tmp += (advSense.getTopics().get(i).get_Words().get(j) + " ");
						}
					}
				}
			}
			if (advSense.hasRegions())
			{
				tmp += "Regions: ";
				for (int i = 0; i < advSense.getRegions().size(); i ++)
				{
					for (int j = 0; j < advSense.getRegions().get(i).get_Words().size(); j ++)
					{
						if (j == advSense.getRegions().get(i).get_Words().size() - 1)
						{
							tmp += (advSense.getRegions().get(i).get_Words().get(j) + ";\n");
						}
						else
						{
							tmp += (advSense.getRegions().get(i).get_Words().get(j) + " ");
						}
					}
				}
			}
			if (advSense.hasUsages())
			{
				tmp += "Usages: ";
				for (int i = 0; i < advSense.getUsages().size(); i ++)
				{
					for (int j = 0; j < advSense.getUsages().get(i).get_Words().size(); j ++)
					{
						if (j == advSense.getUsages().get(i).get_Words().size() - 1)
						{
							tmp += (advSense.getUsages().get(i).get_Words().get(j) + ";\n");
						}
						else
						{
							tmp += (advSense.getUsages().get(i).get_Words().get(j) + " ");
						}
					}
				}
			}
			domainPane.setText(tmp);
			relation.addTab("Domain", domainPane);
		}
	}
}
